package insultGen.systemFiles;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class AddInsult extends Activity{

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addwords);
        
        
        final Spinner select = (Spinner) findViewById(R.id.addOptionSpinner);
        
        final RadioGroup typeSelect = (RadioGroup) findViewById(R.id.add_type);
        
        final EditText Editer = (EditText) findViewById(R.id.add_text);
        
        Button back = (Button) findViewById(R.id.add_back);
        back.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				finish();
			}
		});
        Button add = (Button) findViewById(R.id.add_button);
        add.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				
				addPendingInsult(typeSelect.getCheckedRadioButtonId(), select.getSelectedItemPosition(), Editer.getText().toString());
				
				finish();
			}
		});
	}
	
	public static String getRace(int race){
		if(race == 1){
			return "black";
		}else if(race == 2){
			return "mexican";
		}else if(race == 3){
			return "asian";
		} else if(race == 4){
			return "white";
		} else
			return "none";
	}
	
	public static String getGender(int gender){
		if(gender == 6){
			return "girl";
		} else 
			return "boy";
	}
	
	public static void addPendingInsult(int id1, int id2, String insult){
		String part3 = "";
		String part2 = "";
		String part1 = "";
		
		if (id2 != 0){
			
			if(id2 == 5 || id2 == 6){
				part1 = "gender_";
				part2 = (getGender(id2) + "_");
			}else {
				part1 = "race_";
				part2 = (getRace(id2) + "_");
			}
		}
		if(id1 == R.id.add_type_verb){
			part3 = "verb";
		} else if(id1 == R.id.add_type_noun){
			part3 = "noun";
		} else if(id1 == R.id.add_type_adj){
			part3 = "adj";
		}
		
		Options.addPendingInsult(insult, (part1 + part2 + part3 + ".txt"));
	}
}
